﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Projektet.Controller
{
    class GameController
    {
        View.GameView _gameView;
        View.CatapultView _catapultView;
        Model.EventListener _eventListern;
        SoundController _soundController;
        public Model.GameModel _gameModel;
        public int _levelCount;

        public GameController(Model.EventListener eventListener, int levelCount) 
        {
            _eventListern = eventListener;
            _levelCount = levelCount;
            _gameModel = new Model.GameModel(eventListener, levelCount);
            _gameView = new View.GameView(_gameModel);            
            _soundController = new SoundController();
            if(_levelCount > 1)
            {
                _catapultView = new View.CatapultView(_gameModel._humanPlayer._catapult);
                _gameModel._humanPlayer._catapult._explosionListener = _catapultView;
            }
        }

        public void LoadContent(ContentManager contManager) 
        {
            _gameView.LoadContent(contManager);
            if(_levelCount > 1)
            {
                _catapultView.LoadContent(contManager);
            }
            _soundController.LoadContent(contManager);
            
        }

        public void Update(GameTime gameTime)
        {
            _gameModel.Update(gameTime);
            _soundController.Update(gameTime);
        }

        public void Draw(SpriteBatch spriteBatch) 
        {
            _gameView.Draw(spriteBatch);
            if (_levelCount > 1)
            {
                _catapultView.Draw(spriteBatch);
            }            
        }
    }
}
